sysroot: Port origin writing code to fd-relative
authorColin Walters <walters@verbum.org>
Wed, 14 Sep 2016 01:05:08 +0000 (21:05 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 14 Sep 2016 10:26:39 +0000 (10:26 +0000)
Just preparatory cleanup for a next patch which makes
the fsyncing configurable.

Closes: #509
Approved by: giuseppe

src/libostree/ostree-sysroot-deploy.c
src/libotutil/ot-gio-utils.c
src/libotutil/ot-gio-utils.h

index 79f9c9f3b83e1dcd080b695b4d47006707b2f13b..8f0ff733bd97342bcd98147a69f94de75dbda8cc 100644 (file)
@@ -913,35 +913,32 @@ ostree_sysroot_write_origin_file (OstreeSysroot         *sysroot,
                                   GCancellable          *cancellable,
                                   GError               **error)
 {
-  gboolean ret = FALSE;
   GKeyFile *origin =
     new_origin ? new_origin : ostree_deployment_get_origin (deployment);
 
   if (origin)
     {
-      g_autoptr(GFile) deployment_path = ostree_sysroot_get_deployment_directory (sysroot, deployment);
-      g_autoptr(GFile) origin_path = ostree_sysroot_get_deployment_origin_path (deployment_path);
-      g_autoptr(GFile) origin_parent = g_file_get_parent (origin_path);
+      g_autofree char *origin_path = NULL;
       g_autofree char *contents = NULL;
       gsize len;
-      g_autoptr(GBytes) contents_bytes = NULL;
+
+      origin_path = g_strdup_printf ("ostree/deploy/%s/deploy/%s.%d.origin",
+                                     ostree_deployment_get_osname (deployment),
+                                     ostree_deployment_get_csum (deployment),
+                                     ostree_deployment_get_deployserial (deployment));
 
       contents = g_key_file_to_data (origin, &len, error);
       if (!contents)
-        goto out;
-      contents_bytes = g_bytes_new_static (contents, len);
-
-      if (!ot_gfile_replace_contents_fsync (origin_path, contents_bytes,
-                                            cancellable, error))
-        goto out;
+        return FALSE;
 
-      if (!ot_util_fsync_directory (origin_parent, cancellable, error))
-        goto out;
+      if (!glnx_file_replace_contents_at (sysroot->sysroot_fd,
+                                          origin_path, (guint8*)contents, len,
+                                          GLNX_FILE_REPLACE_DATASYNC_NEW,
+                                          cancellable, error))
+        return FALSE;
     }
 
-  ret = TRUE;
- out:
-  return ret;
+  return TRUE;
 }
 
 static gboolean
index 683fa48eab120dca2895c22231f78a266867d4ef..06bf1a27c4165b1a09adf8451c54ff9ab6338685 100644 (file)
@@ -314,37 +314,6 @@ ot_gfile_ensure_unlinked (GFile         *path,
   return TRUE;
 }
 
-/**
- * ot_util_fsync_directory:
- * @dir: Path to a directory
- * @cancellable: Cancellable
- * @error: Error
- *
- * Ensure that all entries in directory @dir are on disk.
- */
-gboolean
-ot_util_fsync_directory (GFile         *dir,
-                         GCancellable  *cancellable,
-                         GError       **error)
-{
-  gboolean ret = FALSE;
-  glnx_fd_close int dfd = -1;
-
-  if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (dir), TRUE,
-                       &dfd, error))
-    goto out;
-
-  if (fsync (dfd) != 0)
-    {
-      glnx_set_error_from_errno (error);
-      goto out;
-    }
-
-  ret = TRUE;
- out:
-  return ret;
-}
-
 /**
  * ot_util_ensure_directory_and_fsync:
  * @dir: Path to a directory
index 0d3c45d2f9daef47141b7788f5a57a2a6be0cebd..0750a5b47218693a3ececd703bc6d75bc13e9b92 100644 (file)
@@ -89,10 +89,6 @@ gboolean ot_util_ensure_directory_and_fsync (GFile         *dir,
                                              GCancellable  *cancellable,
                                              GError       **error);
 
-gboolean ot_util_fsync_directory (GFile         *dir,
-                                  GCancellable  *cancellable,
-                                  GError       **error);
-
 #if !GLIB_CHECK_VERSION(2, 44, 0)
 gboolean
 ot_file_enumerator_iterate (GFileEnumerator  *direnum,